<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
          * {
            margin: 0;
            padding: 0;
        }

        li {
            list-style: none;
        }
        
        body {
            padding: 200px 400px;
        }
        
        textarea {
            width: 500px;
            height: 200px;
            border: 1px solid rgb(192, 196, 255);
            font-size: 18px;
            outline: none;
            resize: none;
        }
        
        ul {
            margin-top: 50px;
        }
        
        li {
            width: 500px;
            padding: 5px;
            background-color: rgb(209, 245, 218);
            font-size: 14px;
            margin: 5px 0;
        }
    </style>
</head>
<body>
    <textarea name="" id="" cols="30" rows="10"></textarea>
    <button>发布</button>
    <ul>
        <li>比屋教育前端课程</li>
        <li>xxxxx</li>
        <li>xxxxx</li>
        <li>xxxxx</li>
    </ul>

    <script>
        /* 
            思路：
                1.先获取三个对象
                2.给按钮绑定click事件
                3.判断用户输入的评论长度大于3
                4.解决输入空格的问题
                5.将最新发布的内容放到最前面
         */
         const textObj = document.querySelector("textarea")
         const btnObj = document.querySelector("button")
         const ulObj = document.querySelector("ul")

         btnObj.onclick = function(){
            //  console.log(textObj.value)

            if(textObj.value.trim().length>3){      
                //添加
                const liObj = document.createElement("li")
                liObj.innerHTML = textObj.value;
                // ulObj.appendChild(liObj)     //默认插入到末尾
                ulObj.insertBefore(liObj,ulObj.children[0])
            }else{
                //提示
                alert("评论的字数太少了")
            }
         }

    </script>
</body>
</html>